import redis
import pymysql
import json

redis_client = redis.StrictRedis(host='192.168.2.145', port=6379, db='6', password='anRvEdsYPx')
connect = pymysql.connect(host='192.168.2.145', port=3306, db='saas', user='root',
                          password='6yhn^YHN', cursorclass=pymysql.cursors.DictCursor)
cursor = connect.cursor()
sql = """
select deleted, parent_names, parent_code, id, org_path, org_name, full_path, org_code from dam_storage_basic_data_org
"""
cursor.execute(sql)
results = cursor.fetchall()
for result in results:
    if result['deleted'] == 0:
        deleted = False
    else:
        deleted = True
    parent_names = result['parent_names']
    parent_code = result['parent_code']
    sid = result['id']
    org_path = result['org_path']
    org_name = result['org_path']
    full_path = result['full_path']
    org_code = result['org_code']
    hash_data = {"@type": "java.util.HashMap", "deleted": deleted, "parent_names": parent_names,
                 "parent_code": parent_code,
                 "id": sid, "org_path": org_path, "org_name": org_name, "full_path": full_path, "org_code": org_code}
    redis_client.hset("saas:basedata:complete_data:org", org_code, json.dumps(hash_data, ensure_ascii=False))
cursor.close()
connect.close()
redis_client.close()
